/**
 * @author lihuanan.cn
 */
import { DatabaseInfo, DatabaseParams, DatabaseListResultModel } from './model/databaseModel';
import { ContentTypeEnum } from '/@/enums/httpEnum';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  getDatabasePageList = '/api/database/getdatabase',
  saveDatabase = '/database/savedatabase',
  deleteDatabase = '/database/deletedatabase',
}

export const getDatabasePageList = (param: DatabaseParams) => {
  const formData = new FormData();
  formData.append('pageSize', param?.pageSize.toString());
  formData.append('pageIndex', param?.pageIndex.toString());
  if (param?.desc) formData.append('desc', param?.desc);
  return defHttp.post<DatabaseListResultModel>({
    url: Api.getDatabasePageList,
    headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
    params: formData,
  });
};

export const saveDatabase = (params?: DatabaseInfo) =>
  defHttp.post<null>(
    { url: Api.saveDatabase, params },
    {
      errorMessageMode: 'message',
    },
  );

export const deleteDatabase = (params?: Recordable) =>
  defHttp.post<null>({ url: Api.deleteDatabase, params }, { errorMessageMode: 'message' });
